package com.example.demo.mapper;

import com.example.demo.entity.RoleFunction;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface FunctionMapper {
    /**
     * 查询用户功能
     * */
    @Select("SELECT p.*,uf.function_name,uf.function_address FROM permissions AS p LEFT JOIN role_function AS uf ON p.function_id = uf.function_id WHERE p.role_id = (SELECT ur.role_id FROM USER AS u LEFT JOIN user_role AS ur ON u.user_id=ur.user_id WHERE u.user_email = #{user_email}) AND p.permissions_type=1")
    public List<Map> selfunc(String user_email);
    /**
     * 查询角色功能
     * */
    @Select("SELECT p.permissions_id,p.role_id,p.permissions_type,rf.function_name,rf.function_address FROM permissions AS p LEFT JOIN role_function AS rf ON p.function_id = rf.function_id WHERE p.role_id = #{rid}")
    public List<Map> selrolefunc(Integer rid);
    /**
     * 更改角色功能权限
     * */
    @Update("UPDATE permissions SET permissions_type = #{pty} WHERE permissions_id = #{fid}")
    public int upfunc(Integer pty,Integer fid);
    /**
     * 增加用户功能
     * */
    @Insert("insert into role_function values(default,#{function_name},#{function_address},#{role_id},0)")
    public int infunc(String function_name,String function_address,Integer role_id);
}
